package com.dz.lm.service.account.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.dz.lm.common.exception.DaoException;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.service.AbstractService;
import com.dz.lm.service.account.AccountService;

@Service
public class AccountServiceImpl extends AbstractService implements AccountService {
    private static final Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class);
    
    @Resource
    private com.dz.lm.dao.account.read.AccountDao readAccountDao;
    
    @Resource
    private com.dz.lm.dao.account.write.AccountDao writeAccountDao;


    public AccountServiceImpl() {
        System.out.println(">>>>>>>>>>>>>>>>AccountServiceImpl()");
    }
    
    /**
     * 保存账户信息
     * @param param
     * @throws ServiceException
     */
    public void addAccount(Map<String, Object> param) throws ServiceException {
        try {
        	//先按userId查询账户信息
        	Map<String, Object> accountInfo = readAccountDao.qryAccountInfoByUserId(param);
        	if (accountInfo == null || accountInfo.isEmpty()) {
        		param.put("property", "1");//账户性质（1：个人；2：企业）
        		param.put("state", "1");//状态（1 正常 2 冻结 3 注销）
        		//无数据，新增一条
        		writeAccountDao.addAccount(param);
        	}
        } catch (DaoException e) {
            throw  new ServiceException(e,logger);
        }
    }
}
